public class myPow {

    // 递归计算
    public double _myPow(double x, int n) {
        if (n == 0)
            return 1;
        if (n == -1)
            return 1 / x;

        if ((n & 1) == 1)
            return myPow(x * x, n >> 1) * x;
        else
            return _myPow(x * x, n >> 1);
    }

    // 迭代计算
    public double _myPow1(double x, int n) {
        if (x == 0)
            return 0;
        long b = n;
        double res = 1.0;
        if (b < 0) {
            x = 1 / x;
            b = -b;
        }

        while (b > 0) {
            if ((b & 1) == 1)
                res *= x;
            x *= x;
            b = b >> 1;
        }
        return res;
    }
}
